package logic

import (
	"api/model/mysql"
	"context"
	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AminHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAminHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AminHouseLogic {
	return &AminHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AminHouseLogic) AminHouse(in *house.AminHouseHouseRequest) (*house.AminHouseHouseResponse, error) {
	// todo: add your logic here and delete this line

	var houses mysql.House
	mysql.DB.Debug().Where("id=?", in.HouseId).Update("house_status", in.HouseStatus).Find(&houses)

	m := mysql.House{
		HouseStatus: int(in.HouseStatus),
	}

	err := mysql.DB.Debug().Updates(&m)

	if err != nil {
		logx.Error("上架失败")
	}

	return &house.AminHouseHouseResponse{
		Id: int64(m.ID),
	}, nil
}
